package com.cff;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import javax.swing.*;

import com.cff.action.AboutAuthorActionListener;
import com.cff.action.AboutHelpActionListener;
import com.cff.action.AboutReadMeActionListener;
import com.cff.action.CommonKeyValueActionListener;
import com.cff.action.PointGrantActionListener;
import com.cff.action.ProjectAcctActionListener;
import com.cff.action.ProjectSktActionListener;
import com.cff.action.RSAEnOrDecryptActionListener;
import com.cff.action.KeySetActionListener;
import com.cff.action.RSAKeyActionListener;
import com.cff.action.RmbRechargeActionListener;
import com.cff.action.SktAddMsg48ActionListener;
import com.cff.action.SktAddMsgActionListener;
import com.cff.action.SktInfoDownActionListener;
import com.cff.action.SktMsgSendActionListener;
import com.cff.action.SktSocketSendActionListener;
import com.cff.action.imggps.GpsImgActionListener;
import com.cff.common.CacheMemory;
import com.cff.common.Constant;
import com.cff.common.SimpleFrame;
import com.cff.util.EventUtil;
import com.cff.util.FileUtil;
import com.cff.util.TelnetTools;
 
public class AwtPos {
	
	public static String hsmIp = "";
	public static String hsmPort = "";
	public static String transIp = "";
	public static String transPort = "";
	public static String sktIp = "127.0.0.1";
	public static String sktPort = "1111";
	public static String acctIp = "";
	public static String acctPort = "";
	private static String ACCT = "1"; 
	private static String SKT = "0"; 
	private static String PROJECT = "0";
	public static int ACCTWEITH = 0;
	public static int ACCTHEIGH = 0;
	public static int SKTWEITH = 0;
	public static int SKTHEIGH = 0;
	public static int DEFAULTWEITH = 0;
	public static int DEFAULTSKTHEIGH = 0;
	private static Properties confPro = null;
	static{
		Toolkit kit = Toolkit.getDefaultToolkit();  
	    Dimension screenSize = kit.getScreenSize();
	    ACCTHEIGH = screenSize.height/2;
	    ACCTWEITH = screenSize.width/2;
	    SKTWEITH = 1024;
	    SKTHEIGH = 700;
	    DEFAULTWEITH = SKTWEITH;
	    DEFAULTSKTHEIGH = SKTHEIGH;
	}
    public static void main(String[] args) {
    	confPro = FileUtil.getInstance();
        EventQueue.invokeLater(new Runnable(){   //  开一个线程
            public void run() {
            	
            	//控件管理
                SimpleFrame frame = new SimpleFrame(DEFAULTWEITH,DEFAULTSKTHEIGH);
                frame.setTitle(confPro.getProperty("maintitle"));    // 设置title
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
                frame.setLayout(null);
                Panel controlPanel = new Panel();
                controlPanel.setLayout(new FlowLayout());
                controlPanel.setLocation(10, 10);
                controlPanel.setSize(frame.getWidth()-30, frame.getHeight()-30);
                controlPanel.setLayout(null);
                frame.add(controlPanel);
                
                //app1组件
                JButton connectButton = new JButton("trans");   
                JButton acctButton = new JButton("acct");   
                JButton allButton = new JButton("随意");
                final TextArea message = new TextArea();
                final TextArea resultText = new TextArea();
                JLabel portLabel = new JLabel();
                final JTextField portText = new JTextField();
                final JTextField macText = new JTextField();
                Label headerLabel = new Label();
                JLabel macLabel = new JLabel();
                
                //app2组件
        		JLabel labelMsgType = new JLabel();
        		JTextField textMsgType = new JTextField();
        		JLabel labelTranType = new JLabel();
        		JTextField textTranType = new JTextField();
        		JLabel labelTraceNum = new JLabel();
        		JTextField textTraceNum = new JTextField();
        		JLabel labelLocalTime = new JLabel();
        		JTextField textLocalTime = new JTextField();
        		JLabel labelLocalDate = new JLabel();
        		JTextField textLocalDate = new JTextField();
        		JLabel label41 = new JLabel();
        		JTextField text41 = new JTextField();
        		JLabel label42 = new JLabel();
        		JTextField text42 = new JTextField();
        		
        		JLabel label48 = new JLabel();
        		
        		JLabel label48_00 = new JLabel();
        		JTextField text48_00 = new JTextField();
        		JLabel label48_08 = new JLabel();
        		JTextField text48_08 = new JTextField();
        		JLabel label48_09 = new JLabel();
        		JTextField text48_09 = new JTextField();
        		JLabel label48_26 = new JLabel();
        		JTextField text48_26 = new JTextField();
        		JLabel label48_44 = new JLabel();
        		JTextField text48_44 = new JTextField();
        		JButton sktButton = new JButton("发送报文");
        		JButton addSktMsgButton = new JButton("增加域");      		
        		JButton addSktMsg2Button = new JButton(confPro.getProperty("addSktMsg2Button"));
        		JButton sktSocketButton = new JButton("长连接发送报文");
        		
        		for(int i=0;i<20;i++){
					JLabel labelTmp = new JLabel();
					JTextField textTmp = new JTextField();
					CacheMemory.sktJLabel.add(labelTmp);
					CacheMemory.sktJTextField.add(textTmp);
					controlPanel.add(labelTmp);
					controlPanel.add(textTmp);
				}
                if(PROJECT.equals(SKT)){
                	frame.setBounds(10, 10, AwtPos.SKTWEITH, AwtPos.SKTHEIGH);
            		labelMsgType.setBounds(20, 20, 80, 30);
            		labelMsgType.setText(confPro.getProperty("labelMsgType"));
            		textMsgType.setBounds(20, 60, 80, 30);
            		textMsgType.setText(confPro.getProperty("textMsgType"));
            		controlPanel.add(labelMsgType);
            		controlPanel.add(textMsgType);
            		
            		labelTranType.setBounds(130, 20, 90, 30);
            		labelTranType.setText(confPro.getProperty("labelTranType"));
            		textTranType.setBounds(130, 60, 90, 30);
            		textTranType.setText(confPro.getProperty("textTranType"));
            		controlPanel.add(labelTranType);
            		controlPanel.add(textTranType);
            		
            		labelTraceNum.setBounds(250, 20, 90, 30);
            		labelTraceNum.setText(confPro.getProperty("labelTraceNum"));
            		textTraceNum.setBounds(250, 60, 90, 30);
            		textTraceNum.setText(confPro.getProperty("textTraceNum"));
            		controlPanel.add(labelTraceNum);
            		controlPanel.add(textTraceNum);
            		
            		labelLocalTime.setBounds(370, 20, 90, 30);
            		labelLocalTime.setText(confPro.getProperty("labelLocalTime"));
            		textLocalTime.setBounds(370, 60, 90, 30);
            		textLocalTime.setText(confPro.getProperty("textLocalTime"));
            		controlPanel.add(labelLocalTime);
            		controlPanel.add(textLocalTime);
            		
            		labelLocalDate.setBounds(480, 20, 90, 30);
            		labelLocalDate.setText(confPro.getProperty("labelLocalDate"));
            		textLocalDate.setBounds(480, 60, 90, 30);
            		textLocalDate.setText(confPro.getProperty("textLocalDate"));
            		controlPanel.add(labelLocalDate);
            		controlPanel.add(textLocalDate);
            		
            		label41.setBounds(600, 20, 90, 30);
            		label41.setText(confPro.getProperty("label41"));
            		text41.setBounds(600, 60, 90, 30);
            		text41.setText(confPro.getProperty("text41"));
            		controlPanel.add(label41);
            		controlPanel.add(text41);
            		
            		label42.setBounds(720, 20, 110, 30);
            		label42.setText(confPro.getProperty("label42"));
            		text42.setBounds(720, 60, 110, 30);
            		text42.setText(confPro.getProperty("text42"));
            		controlPanel.add(label42);
            		controlPanel.add(text42);
            		
            		label48.setBounds(400, 250, 110, 30);
            		label48.setText(confPro.getProperty("label48"));
            		controlPanel.add(label48);
            		
            		label48_00.setBounds(20, 280, 100, 30);
            		label48_00.setText(confPro.getProperty("label48_00"));
            		text48_00.setBounds(20, 320, 100, 30);
            		text48_00.setText(confPro.getProperty("text48_00"));
            		controlPanel.add(label48_00);
            		controlPanel.add(text48_00);
            		
            		label48_08.setBounds(150, 280, 100, 30);
            		label48_08.setText(confPro.getProperty("label48_08"));
            		text48_08.setBounds(150, 320, 100, 30);
            		text48_08.setText(confPro.getProperty("text48_08"));
            		controlPanel.add(label48_08);
            		controlPanel.add(text48_08);
            		
            		label48_09.setBounds(280, 280, 100, 30);
            		label48_09.setText(confPro.getProperty("label48_09"));
            		text48_09.setBounds(280, 320, 100, 30);
            		text48_09.setText(confPro.getProperty("text48_09"));
            		controlPanel.add(label48_09);
            		controlPanel.add(text48_09);
            		
            		label48_26.setBounds(410, 280, 100, 30);
            		label48_26.setText(confPro.getProperty("label48_26"));
            		text48_26.setBounds(410, 320, 100, 30);
            		text48_26.setText(confPro.getProperty("text48_26"));
            		controlPanel.add(label48_26);
            		controlPanel.add(text48_26);
            		
            		label48_44.setBounds(540, 280, 100, 30);
            		label48_44.setText(confPro.getProperty("label48_44"));
            		text48_44.setBounds(540, 320, 100, 30);
            		text48_44.setText(confPro.getProperty("text48_44"));
            		controlPanel.add(label48_44);
            		controlPanel.add(text48_44);
            		
            		sktButton.setBounds(300, 500, 150, 40);
            		controlPanel.add(sktButton);
            		sktSocketButton.setBounds(600, 500, 150, 40);
            		controlPanel.add(sktSocketButton);
            		addSktMsgButton.setBounds(880, 60, 100, 40);
            		controlPanel.add(addSktMsgButton);
            		addSktMsg2Button.setBounds(880, 310, 100, 40);
            		controlPanel.add(addSktMsg2Button);
            		
                }else if(PROJECT.equals(ACCT)){
                	frame.setBounds(100, 100, AwtPos.ACCTWEITH, AwtPos.ACCTHEIGH);
            		controlPanel.add(connectButton);
                    controlPanel.add(acctButton);
                    controlPanel.add(allButton);
                    connectButton.setBounds(160,270,80,30);
                    acctButton.setBounds(280,270,80,30);
                    allButton.setBounds(400,270,80,30);
                    message.setBounds(50, 60, controlPanel.getWidth()-100, 80);
                    headerLabel.setBounds(50, 150, 50, 50);
                    headerLabel.setText("result:");
                    resultText.setBounds(120, 180, controlPanel.getWidth()-200, 80);
                    controlPanel.add(message);
                    controlPanel.add(headerLabel);
                    controlPanel.add(resultText);
                    portLabel.setBounds(10, 1, 220, 50);
                    portLabel.setText("端口号：");
                    portText.setBounds(235, 8, 80, 30);
                    portText.setText(confPro.getProperty("portText"));
                    macLabel.setBounds(360, 1, 80, 50);
                    macLabel.setText("mac密钥：");
                    macText.setBounds(450, 8, 150, 30);
                    macText.setText(confPro.getProperty("macText"));
                    controlPanel.add(portLabel);
                    controlPanel.add(portText);
                    controlPanel.add(macLabel);
                    controlPanel.add(macText);
                }
                
                //添加菜单
                JMenuBar bar = new JMenuBar();
                JMenu menu = new JMenu("文件");
                JMenu projectMenu = new JMenu("系统");
                JMenu configMenu = new JMenu("系统配置");
                JMenu signMenu = new JMenu("加密");
                JMenu keyConfigMenu = new JMenu("密钥配置");
                JMenu transMenu = new JMenu("交易");
                JMenu boxMenu = new JMenu("密保箱");
                JMenu aboutMenu = new JMenu("关于");
                JMenu appMenu = new JMenu("应用");
                JMenuItem openFileitem = new JMenuItem("打开");
                JMenuItem Acctitem = new JMenuItem(confPro.getProperty("app1"));
                JMenuItem Sktitem = new JMenuItem(confPro.getProperty("app2"));
                JMenuItem configHsmItem = new JMenuItem("加密机配置");
                JMenuItem sktDestMenu = new JMenuItem(confPro.getProperty("app2dest"));
                JMenuItem configDestMenu = new JMenu(confPro.getProperty("app1dest"));
                JMenuItem configTransItem = new JMenuItem(confPro.getProperty("app11conf"));
                JMenuItem configAcctItem = new JMenuItem(confPro.getProperty("app12conf"));
                JMenuItem RSApublicEncryptItem = new JMenuItem("RSA公钥加密");
                JMenuItem RSApublicEncryptToQQItem = new JMenuItem("RSA公钥加密并放到QQ");
                JMenuItem RSAprivateDecryptItem = new JMenuItem("RSA私钥解密");
                JMenuItem publicEncryptItem = new JMenuItem("测试环境公钥加密");
                JMenuItem publicEncryptProcItem = new JMenuItem("生产环境公钥加密");
                JMenuItem publicDecryptItem = new JMenuItem("测试环境私钥解密");
                JMenuItem publicEncryptKeyItem = new JMenuItem("测试环境公钥配置");
                JMenuItem publicEncryptProcKeyItem = new JMenuItem("生产环境公钥配置");
                JMenuItem publicDecryptKeyItem = new JMenuItem("测试环境私钥配置");
                JMenuItem pointGrantItem = new JMenuItem(confPro.getProperty("tran1"));
                JMenuItem rmbRechargeItem = new JMenuItem(confPro.getProperty("tran2"));
                JMenuItem sktInfoDownTestItem = new JMenuItem(confPro.getProperty("tran3"));
                JMenuItem boxVerify = new JMenuItem("验证");
                JMenuItem aboutAuthorItem = new JMenuItem("关于作者");
                JMenuItem readMeItem = new JMenuItem("使用方法");
                JMenuItem helpItem = new JMenuItem("端口和MAC");
                JMenuItem gpsImgItem = new JMenuItem("图片定位");
                menu.add(openFileitem);
                configMenu.add(configHsmItem);
                configMenu.add(configDestMenu);
                configMenu.add(sktDestMenu);
                configDestMenu.add(configTransItem);
                configDestMenu.add(configAcctItem);
                signMenu.add(RSApublicEncryptItem);
                signMenu.add(RSAprivateDecryptItem);
                signMenu.add(RSApublicEncryptToQQItem);
                signMenu.add(publicEncryptItem);
                signMenu.add(publicEncryptProcItem);
                signMenu.add(publicDecryptItem);
                keyConfigMenu.add(publicEncryptKeyItem);
                keyConfigMenu.add(publicEncryptProcKeyItem);
                keyConfigMenu.add(publicDecryptKeyItem);
                transMenu.add(pointGrantItem);
                transMenu.add(rmbRechargeItem);
                transMenu.add(sktInfoDownTestItem);
                aboutMenu.add(aboutAuthorItem);
                aboutMenu.add(readMeItem);
                aboutMenu.add(helpItem);
                appMenu.add(gpsImgItem);
                projectMenu.add(Acctitem);
                projectMenu.add(Sktitem);
                boxMenu.add(boxVerify);
                bar.add(menu);
                bar.add(projectMenu);
                bar.add(configMenu);
                bar.add(signMenu);
                bar.add(keyConfigMenu);
                bar.add(transMenu);
                bar.add(boxMenu);
                bar.add(aboutMenu);
                bar.add(appMenu);

                frame.setJMenuBar(bar);
                
                //添加加密机配置监听、
                configHsmItem.addActionListener(new ActionListener(){
					@Override
					public void actionPerformed(ActionEvent e) {
						final JFrame tmpFrame = new JFrame();
						tmpFrame.setBounds(300, 300, 300, 200);
						tmpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
						tmpFrame.setLayout(null);
						
						JLabel hsmIpLabel = new JLabel();
						hsmIpLabel.setBounds(20, 20, 80, 50);
						hsmIpLabel.setText("加密机IP:");
						
						JLabel hsmPortLabel = new JLabel();
						hsmPortLabel.setBounds(20, 70, 80, 50);
						hsmPortLabel.setText("加密机Port:");
						
						final JTextField hsmIpText = new JTextField();
						hsmIpText.setBounds(100, 35, 180, 20);
						
						final JTextField hsmPortText = new JTextField();
						hsmPortText.setBounds(100, 85, 180, 20);
						
						JButton okButton = new JButton("ok"); 
						okButton.setBounds(tmpFrame.getWidth()/2-50, tmpFrame.getHeight()-80, 50, 25);
						
						tmpFrame.add(hsmIpLabel);
						tmpFrame.add(hsmPortLabel);
						tmpFrame.add(hsmIpText);
						tmpFrame.add(hsmPortText);
						tmpFrame.add(okButton);
						
						//添加按钮监听
						okButton.addActionListener(new ActionListener() {
							@Override
							public void actionPerformed(ActionEvent e) {
								hsmIp = hsmIpText.getText();
								hsmPort = hsmPortText.getText();
								tmpFrame.dispatchEvent(new WindowEvent(tmpFrame,WindowEvent.WINDOW_CLOSING) );
							}
		                   }
						);
						
						
						tmpFrame.setVisible(true);
					}
                	
                });
                
              //添加app11配置监听、
                configTransItem.addActionListener(new ActionListener(){
					@Override
					public void actionPerformed(ActionEvent e) {
						final JFrame tmpFrame = new JFrame();
						tmpFrame.setBounds(300, 300, 300, 200);
						tmpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
						tmpFrame.setLayout(null);
						
						JLabel hsmIpLabel = new JLabel();
						hsmIpLabel.setBounds(20, 20, 80, 50);
						hsmIpLabel.setText(confPro.getProperty("app11ipDesc"));
						
						JLabel hsmPortLabel = new JLabel();
						hsmPortLabel.setBounds(20, 70, 80, 50);
						hsmPortLabel.setText(confPro.getProperty("app11portDesc"));
						
						final JTextField hsmIpText = new JTextField();
						hsmIpText.setBounds(100, 35, 180, 20);
						
						final JTextField hsmPortText = new JTextField();
						hsmPortText.setBounds(100, 85, 180, 20);
						
						JButton okButton = new JButton("ok"); 
						okButton.setBounds(tmpFrame.getWidth()/2-50, tmpFrame.getHeight()-80, 50, 25);
						
						tmpFrame.add(hsmIpLabel);
						tmpFrame.add(hsmPortLabel);
						tmpFrame.add(hsmIpText);
						tmpFrame.add(hsmPortText);
						tmpFrame.add(okButton);
						
						//添加按钮监听
						okButton.addActionListener(new ActionListener() {
							@Override
							public void actionPerformed(ActionEvent e) {
								transIp = hsmIpText.getText();
								transPort = hsmPortText.getText();
								tmpFrame.dispatchEvent(new WindowEvent(tmpFrame,WindowEvent.WINDOW_CLOSING) );
							}
		                   }
						);
						
						
						tmpFrame.setVisible(true);
					}
                	
                });
                
              //添加app2配置监听、
                sktDestMenu.addActionListener(new ActionListener(){
					@Override
					public void actionPerformed(ActionEvent e) {
						final JFrame tmpFrame = new JFrame();
						tmpFrame.setBounds(300, 300, 300, 200);
						tmpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
						tmpFrame.setLayout(null);
						
						JLabel hsmIpLabel = new JLabel();
						hsmIpLabel.setBounds(20, 20, 80, 50);
						hsmIpLabel.setText(confPro.getProperty("app2ipDesc"));
						
						JLabel hsmPortLabel = new JLabel();
						hsmPortLabel.setBounds(20, 70, 80, 50);
						hsmPortLabel.setText(confPro.getProperty("app2portDesc"));
						
						final JTextField hsmIpText = new JTextField();
						hsmIpText.setBounds(100, 35, 180, 20);
						hsmIpText.setText(confPro.getProperty("app2ip"));
						
						final JTextField hsmPortText = new JTextField();
						hsmPortText.setBounds(100, 85, 180, 20);
						hsmPortText.setText(confPro.getProperty("app2port"));
						
						JButton okButton = new JButton("ok"); 
						okButton.setBounds(tmpFrame.getWidth()/2-50, tmpFrame.getHeight()-80, 50, 25);
						
						tmpFrame.add(hsmIpLabel);
						tmpFrame.add(hsmPortLabel);
						tmpFrame.add(hsmIpText);
						tmpFrame.add(hsmPortText);
						tmpFrame.add(okButton);
						
						//添加按钮监听
						okButton.addActionListener(new ActionListener() {
							@Override
							public void actionPerformed(ActionEvent e) {
								sktIp = hsmIpText.getText();
								sktPort = hsmPortText.getText();
								tmpFrame.dispatchEvent(new WindowEvent(tmpFrame,WindowEvent.WINDOW_CLOSING) );
							}
		                   }
						);
						
						
						tmpFrame.setVisible(true);
					}
                	
                });
                
              //添加app12配置监听、
                configAcctItem.addActionListener(new ActionListener(){
					@Override
					public void actionPerformed(ActionEvent e) {
						final JFrame tmpFrame = new JFrame();
						tmpFrame.setBounds(300, 300, 300, 200);
						tmpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
						tmpFrame.setLayout(null);
						
						JLabel hsmIpLabel = new JLabel();
						hsmIpLabel.setBounds(20, 20, 80, 50);
						hsmIpLabel.setText(confPro.getProperty("app12ipDesc"));
						
						JLabel hsmPortLabel = new JLabel();
						hsmPortLabel.setBounds(20, 70, 80, 50);
						hsmPortLabel.setText(confPro.getProperty("app12portDesc"));
						
						final JTextField hsmIpText = new JTextField();
						hsmIpText.setBounds(100, 35, 180, 20);
						
						final JTextField hsmPortText = new JTextField();
						hsmPortText.setBounds(100, 85, 180, 20);
						
						JButton okButton = new JButton("ok"); 
						okButton.setBounds(tmpFrame.getWidth()/2-50, tmpFrame.getHeight()-80, 50, 25);
						
						tmpFrame.add(hsmIpLabel);
						tmpFrame.add(hsmPortLabel);
						tmpFrame.add(hsmIpText);
						tmpFrame.add(hsmPortText);
						tmpFrame.add(okButton);
						
						//添加按钮监听
						okButton.addActionListener(new ActionListener() {
							@Override
							public void actionPerformed(ActionEvent e) {
								acctIp = hsmIpText.getText();
								acctPort = hsmPortText.getText();
								tmpFrame.dispatchEvent(new WindowEvent(tmpFrame,WindowEvent.WINDOW_CLOSING) );
							}
		                   }
						);
						
						
						tmpFrame.setVisible(true);
					}
                	
                });
                
              //添加打开文件监听、
                openFileitem.addActionListener(new ActionListener(){
					@Override
					public void actionPerformed(ActionEvent e) {
						JFileChooser jfc=new JFileChooser();  
				        jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES );  
				        jfc.showDialog(new JLabel(), "选择");  
				        File file=jfc.getSelectedFile();  
				        if(file == null)return;
				        if(file.isDirectory()){  
				            System.out.println("文件夹:"+file.getAbsolutePath());  
				            return;
				        }else if(file.isFile()){  
				            System.out.println("文件:"+file.getAbsolutePath());  				            
				        }  
				       
				        //读文件并存入map
				        final Map<String, ArrayList> msgBuffer = new HashMap<String,ArrayList>();
				        String str2 = "\n";
				        String str3 = "\n";
				        InputStreamReader read = null;
						try {
							read = new InputStreamReader(new FileInputStream(file),"gbk");
						} catch (UnsupportedEncodingException e2) {
							e2.printStackTrace();
						} catch (FileNotFoundException e2) {
							e2.printStackTrace();
						}       
			            BufferedReader br=new BufferedReader(read); 
						try {        		
					        while (str2 != null) {   			   
					            if(str3 != null && !"\n".equals(str3) && (str3.contains(":")||str3.contains("：")))
					            	str2 = str3;
					        	else
					        		str2 = br.readLine();  
					           // System.out.println(str2);
					            if(str2 != null && !"\n".equals(str2) && (str2.contains(":")||str2.contains("："))){
					            	String tmpKey = str2.substring(0, str2.length()-1);
					            	//System.out.println("tmpKey:"+ tmpKey);
					            	ArrayList<String> tmpData = new ArrayList<String>();
					            	msgBuffer.put(tmpKey, tmpData);				            	
					            	str3 = br.readLine();
					            	//System.out.println(str3);
					            	while (str3 != null && !(str3.contains(":")||str3.contains("：")) && !"\n".equals(str3) ){		
					            		tmpData.add(str3);
					            		str3 = br.readLine();
					            	}					            	
					            }
					            	
					        }  
						} catch (IOException e1) {
							e1.printStackTrace();
						}  
				        try {
							br.close();						 
							read.close(); 
				        } catch (IOException e1) {
							e1.printStackTrace();
						}  
				       		
				        System.out.println(msgBuffer.toString());
				        //添加显示窗口
				        JFrame tmpFrame = new JFrame();
						tmpFrame.setBounds(200, 50, 800, 660);
						tmpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
						tmpFrame.setLayout(null);
						final JComboBox msgAll = new JComboBox(); 
						final TextArea textMsg = new TextArea();
						msgAll.setBounds(10, 10, 200, 30);
						textMsg.setBounds(300, 10, 400, 300);
						msgAll.setEditable(true);
						Set msgKeySet = msgBuffer.keySet();
						Iterator i = msgKeySet.iterator();         
						while(i.hasNext()){      					         
						     msgAll.addItem(i.next());  
						}
						msgAll.addActionListener(new ActionListener() {
						      public void actionPerformed(final ActionEvent e) {
						        int index = msgAll.getSelectedIndex();
						        if (index != 0) { // ==0表示选中的事第一个
						        	String content = msgAll.getSelectedItem().toString();
						        	textMsg.setText("");
						        	for(int i=0;i<msgBuffer.get(content).size();i++){
						        		textMsg.append(msgBuffer.get(content).get(i).toString());
						        		textMsg.append("\n");
						        	}
						        	
						        }

						      }
					    });
						tmpFrame.add(msgAll);
						tmpFrame.add(textMsg);
						tmpFrame.setVisible(true);
					}
                	
                });
                
                //添加窗体监听
                frame.addKeyListener(new KeyAdapter()//键盘监听按钮
				{
				    public void keyPressed(KeyEvent e)
				     {
				         //组合键
				         if(e.isControlDown()&&e.getKeyCode()==KeyEvent.VK_ENTER){
				        	 System.out.println(e.getKeyChar()+"..."+KeyEvent.getKeyText(e.getKeyCode()));
				         }
				    }
				             
				});
                //添加按钮监听
				connectButton.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						String data = message.getText();
						if((data == null)||"".equals(data)){
							JOptionPane.showMessageDialog(null,"数据输入为空！");
							return;
						}
						TelnetTools telnetTools = new TelnetTools();
						if("".equals(hsmIp)){
							telnetTools.setHsmIp(confPro.getProperty("hsmip"));
						}else{
							telnetTools.setHsmIp(hsmIp);
						}
						if("".equals(hsmPort)){
							telnetTools.setHsmPort(confPro.getProperty("hsmport"));
						}else{
							telnetTools.setHsmPort(hsmPort);
						}
						if("".equals(transIp)){
							telnetTools.setDestIp(confPro.getProperty("app11ip"));
						}else{
							telnetTools.setDestIp(transIp);
						}
						if("".equals(transPort)){
							telnetTools.setDestPort(confPro.getProperty("app11port"));
						}else{
							telnetTools.setDestPort(transPort);
						}
						String result = telnetTools.trans(data, telnetTools);
						//macLabel.setText("HAHA");
						resultText.setText(result);
					}
                   }
				);
				//添加按钮监听
				acctButton.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						String data = message.getText();
						if((data == null)||"".equals(data)){
							JOptionPane.showMessageDialog(null,"数据输入为空！");
							return;
						}
						TelnetTools telnetTools = new TelnetTools();
						if("".equals(hsmIp)){
							telnetTools.setHsmIp(confPro.getProperty("hsmip"));
						}else{
							telnetTools.setHsmIp(hsmIp);
						}
						if("".equals(hsmPort)){
							telnetTools.setHsmPort(confPro.getProperty("hsmport"));
						}else{
							telnetTools.setHsmPort(hsmPort);
						}
						if("".equals(acctIp)){
							telnetTools.setDestIp(confPro.getProperty("app12ip"));
						}else{
							telnetTools.setDestIp(acctIp);
						}
						if("".equals(acctPort)){
							telnetTools.setDestPort(confPro.getProperty("app12port"));
						}else{
							telnetTools.setDestPort(acctPort);
						}
						
						String result = telnetTools.acct(data);						
						//macLabel.setText("HAHA");
						resultText.setText(result);
					}
                   }
				);
				 //添加按钮监听
				allButton.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						String data = message.getText();
						if((data == null)||"".equals(data)){
							JOptionPane.showMessageDialog(null,"数据输入为空！");
							return;
						}
						TelnetTools telnetTools = new TelnetTools();
						if("".equals(hsmIp)){
							telnetTools.setHsmIp(confPro.getProperty("hsmip"));
						}else{
							telnetTools.setHsmIp(hsmIp);
						}
						if("".equals(hsmPort)){
							telnetTools.setHsmPort(confPro.getProperty("hsmip"));
						}else{
							telnetTools.setHsmPort(hsmPort);
						}
						if("".equals(transIp)){
							telnetTools.setDestIp(confPro.getProperty("app11ip"));
						}else{
							telnetTools.setDestIp(transIp);
						}
						if("".equals(portText.getText().trim())){
							telnetTools.setDestPort(confPro.getProperty("portText"));
						}else{
							telnetTools.setDestPort(portText.getText().trim());
						}
						String mactext = macText.getText().trim();
						if("".equals(mactext)){
							JOptionPane.showMessageDialog(null,"数据输入为空！");
							return;
						}
						String result = telnetTools.allSend(data,mactext);
						//macLabel.setText("HAHA");
						resultText.setText(result);
					}
                   }
				);
				
				ActionListener publicEncryptKeySetAction = new KeySetActionListener(Constant.PUBLICKEY);
				EventUtil.putEvent(publicEncryptKeyItem, publicEncryptKeySetAction);
				
				ActionListener privateKeySetAction = new KeySetActionListener(Constant.PRIVATEKEY);
				EventUtil.putEvent(publicDecryptKeyItem, privateKeySetAction);
				
				ActionListener publicProcEncryptKeySetAction = new KeySetActionListener(Constant.PUBLICPROCKEY);
				EventUtil.putEvent(publicEncryptProcKeyItem, publicProcEncryptKeySetAction);
				
				ActionListener privateDecryptAction = new RSAKeyActionListener(Constant.PRIVATEKEY);
				EventUtil.putEvent(publicDecryptItem, privateDecryptAction);
				
				ActionListener publicEncryptAction = new RSAKeyActionListener(Constant.PUBLICKEY);
				EventUtil.putEvent(publicEncryptItem, publicEncryptAction);
				
				ActionListener RSApublicEncryptAction = new RSAKeyActionListener(Constant.RSAPUBLICKEY);
				EventUtil.putEvent(RSApublicEncryptItem, RSApublicEncryptAction);
				
				ActionListener rSApublicEncryptToQQ = new RSAKeyActionListener(Constant.RSAPUBLICKEYQQ);
				EventUtil.putEvent(RSApublicEncryptToQQItem, rSApublicEncryptToQQ);
				
				ActionListener RSAprivateDecryptAction = new RSAKeyActionListener(Constant.RSAPRIVATEKEY);
				EventUtil.putEvent(RSAprivateDecryptItem, RSAprivateDecryptAction);
				
				ActionListener commonKeyValueActionListener = new CommonKeyValueActionListener(Constant.BOXVERIFY);
				EventUtil.putEvent(boxVerify, commonKeyValueActionListener);
				
				ActionListener publicProcEncryptAction = new RSAKeyActionListener(Constant.PUBLICPROCKEY);
				EventUtil.putEvent(publicEncryptProcItem, publicProcEncryptAction);
				
				ActionListener pointGrantActionListener = new PointGrantActionListener();
				EventUtil.putEvent(pointGrantItem, pointGrantActionListener);
				
				ActionListener aboutAuthorActionListener = new AboutAuthorActionListener();
				EventUtil.putEvent(aboutAuthorItem, aboutAuthorActionListener);
				
				ActionListener aboutReadMeActionListener = new AboutReadMeActionListener();
				EventUtil.putEvent(readMeItem, aboutReadMeActionListener);
				
				ActionListener aboutHelpActionListener = new AboutHelpActionListener();
				EventUtil.putEvent(helpItem, aboutHelpActionListener);
				
				ActionListener rmbRechargeActionListener = new RmbRechargeActionListener();
				EventUtil.putEvent(rmbRechargeItem, rmbRechargeActionListener);
				
				ActionListener sktInfoDownActionListener = new SktInfoDownActionListener();
				EventUtil.putEvent(sktInfoDownTestItem, sktInfoDownActionListener);
				
				ActionListener projectAcctActionListener = new ProjectAcctActionListener(frame,controlPanel, 
						connectButton,acctButton,allButton,message,resultText, portLabel, portText,  
						macText,headerLabel,  macLabel);
				EventUtil.putEvent(Acctitem, projectAcctActionListener);
				
				ActionListener projectSktActionListener = new ProjectSktActionListener(frame,controlPanel,
						labelMsgType, textMsgType, labelTranType, textTranType, labelTraceNum, 
						textTraceNum, labelLocalTime, textLocalTime, labelLocalDate, textLocalDate, 
						label41, text41, label42, text42,label48,label48_00, text48_00, label48_08, 
						text48_08, label48_09, text48_09, label48_26, text48_26, label48_44, 
						text48_44,sktButton, addSktMsgButton, addSktMsg2Button);
				EventUtil.putEvent(Sktitem, projectSktActionListener);
				
				ActionListener sktMsgSendActionListener = new SktMsgSendActionListener(frame,controlPanel,
						labelMsgType, textMsgType, labelTranType, textTranType, labelTraceNum, 
						textTraceNum, labelLocalTime, textLocalTime, labelLocalDate, textLocalDate, 
						label41, text41, label42, text42,label48,label48_00, text48_00, label48_08, 
						text48_08, label48_09, text48_09, label48_26, text48_26, label48_44, text48_44,sktButton);
				EventUtil.putEvent(sktButton, sktMsgSendActionListener);
				
				ActionListener sktSocketSendActionListener = new SktSocketSendActionListener(frame,controlPanel,
						labelMsgType, textMsgType, labelTranType, textTranType, labelTraceNum, 
						textTraceNum, labelLocalTime, textLocalTime, labelLocalDate, textLocalDate, 
						label41, text41, label42, text42,label48,label48_00, text48_00, label48_08, 
						text48_08, label48_09, text48_09, label48_26, text48_26, label48_44, text48_44,sktButton);
				EventUtil.putEvent(sktSocketButton, sktSocketSendActionListener);
				
				ActionListener sktAddMsgActionListener = new SktAddMsgActionListener(controlPanel);
				EventUtil.putEvent(addSktMsgButton, sktAddMsgActionListener);
				
				ActionListener sktAddMsg48ActionListener = new SktAddMsg48ActionListener(controlPanel);
				EventUtil.putEvent(addSktMsg2Button, sktAddMsg48ActionListener);
				
				ActionListener gpsImgActionListener = new GpsImgActionListener();
				EventUtil.putEvent(gpsImgItem, gpsImgActionListener);
				
                frame.setVisible(true);
            }
        });
    }
    

    public void InitConstant(){
    	Constant.acctPublicKey = confPro.getProperty("acctPublicKey");
    	Constant.acctPrivateKey = confPro.getProperty("acctPrivateKey");
    	Constant.acctPublicProcKey = confPro.getProperty("acctPublicProcKey");
    	Constant.RSAPublicKey = confPro.getProperty("RSAPublicKey");
    	Constant.RSAPrivateKey = confPro.getProperty("RSAPrivateKey");
    }
}
 

